package com.action;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;

import com.model.User;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.service.UserService;

@Controller
@Transactional
public class RegistAction extends ActionSupport {
	
	@Resource private UserService userservice;

	private static final long serialVersionUID = 1L;
	
	private String username;
	private String password;
	private String password2;
	private String userclass;
	
	public String execute() {			
		ActionContext context = ActionContext.getContext();// 获取action上下文
		Map<String, Object> session = context.getSession(); //获取sesion
		// HttpServletRequest request = (HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST);		 
		//HttpServletResponse response = (HttpServletResponse)context.get(ServletActionContext.HTTP_RESPONSE);
		HttpServletRequest request=(HttpServletRequest)context.get(ServletActionContext.HTTP_REQUEST);
		username=request.getParameter("username").toString();
		password=request.getParameter("password").toString();
		password2=request.getParameter("password2").toString();
		userclass=request.getParameter("userclass").toString();
		if(password.equals(password2)){
			session.put("username", username);
			session.put("password", password);
			session.put("userclass", userclass);	
			User user=new User();
			user.setUsername(username);
			user.setPassword(password);
			user.setUserclass(userclass);
			userservice.add(user);
		}
		return SUCCESS;
	}
}
